package com.Spring.SpringSpms.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;
import com.Spring.SpringSpms.model.*;
import com.Spring.SpringSpms.dao.*;

@Controller
public class HomeController {

	@Autowired
	private ProjectDAO projectDAO;
	@Autowired
	private StatusDAO statusDAO;
	@Autowired
	private StoryPointsDAO storypointsDAO;
	@Autowired
	private TaskDAO taskDAO;
	@Autowired
	private StoryDAO storyDAO;
	@Autowired
	private SprintPlanningDAO sprintDAO;
	@Autowired
	private ComplexityDAO complexityDAO;
	@Autowired
	private PriorityDAO priorityDAO;
	@Autowired
	private DesignationDAO designationDAO;
	//@Autowired
	//private EmployeeDAO employeeDAO;
	@Autowired
	private RoleDAO roleDAO;
	@Autowired
	private PlatFormDAO platformDAO;
	@Autowired
	private EmployeeDAO employeeDAO;
	@Autowired
	private HttpSession httpSession;
	@Autowired
	private ClientDAO clientDAO;

//***************************Login Page***************************
	@RequestMapping(value="/")
	public ModelAndView listProject(ModelAndView model,HttpSession httpSession) throws IOException{
		List<Role> listRole = roleDAO.list();
		model.addObject("listRole", listRole);
		model.setViewName("home");
		Employee emp = new Employee();
		model.addObject("employee",emp);
		return model;
	}




	@RequestMapping(value="/validate",method=RequestMethod.POST)
	public ModelAndView validate(@ModelAttribute Employee employee,@ModelAttribute("roleId") Integer roleId,HttpSession httpSession)
	{
		int b=employeeDAO.loginTest(employee,roleId);
		System.out.print("emp_id is:"+b);
		if(b > 0)
		{	
			httpSession.setAttribute("empid",b);
			String name=roleDAO.getRoleName(roleId);

			if(name.equals("Admin"))
			{
				return new ModelAndView("/Admin");
			}
			else if(name.equals("Manager"))
			{
				return new ModelAndView("redirect:/Project");
			}
			else if(name.equals("Employee"))
				return new ModelAndView("redirect:/ProjectEmp");

		}
		else
		{

			return new ModelAndView("redirect:/");  
		}
		return new ModelAndView("redirect:/");  

	}
	
	//***************************Project backlog page for employees***************************
	@RequestMapping(value="/ProjectEmp")
	public ModelAndView ProjectEmp(ModelAndView model) throws IOException{
		int empid=(Integer) httpSession.getAttribute("empid");
		System.out.println("empid in project is:"+empid);

		List<Project> listProject = projectDAO.list(empid);
		model.addObject("listProject", listProject);
		
		//list of all the project status 
		List<String> listprojstatus=statusDAO.listProjectStatus(empid);
		model.addObject("projectStatus", listprojstatus);

		//list of all the client names
		List<String> listprojclient=projectDAO.listClient(empid);
		model.addObject("listClient",listprojclient);

		List<PlatForm> listplatform = platformDAO.list();
		model.addObject("listplatform", listplatform);

		model.setViewName("ProjectEmp");

		return model;
	}

	@RequestMapping(value="/CreateProject")
	public ModelAndView CreateProject(ModelAndView model) throws IOException{
	
		Project newProject = new Project();
		model.addObject("project",newProject);

		List<Client> clientList = clientDAO.list();
		model.addObject("clientList", clientList);

		List<Status> statusList = statusDAO.list();
		model.addObject("statusList", statusList);

		List<Employee> employeeList = employeeDAO.list();
		model.addObject("employeeList", employeeList);

		List<Role> roleList = roleDAO.list();
		model.addObject("roleList", roleList);

		List<PlatForm> platformList = platformDAO.list();
		model.addObject("platformList", platformList);

		model.setViewName("CreateProject");
		return model;

	}
	@RequestMapping(value="/saveProject", method=RequestMethod.POST)
	public ModelAndView saveProject(@ModelAttribute Project project ,HttpServletRequest request,ModelAndView model) throws IOException{

		String Employee_Ids[]=request.getParameterValues("check");
		String Role_names[]=request.getParameterValues("radio1");
		String Platform_Ids[]=request.getParameterValues("check1");

		
		for(int i=0;i<Role_names.length;i++)
		{
			System.out.println("Role Name :"+Role_names[i]);
		}
		for(int i=0;i<Employee_Ids.length;i++)
		{
			System.out.println("In home controller emp id " +Employee_Ids[i]+"Specific role "+Role_names[i]);

		}



		for(int i=0;i<Platform_Ids.length;i++)
		{
			System.out.println("Platform id's are "+Platform_Ids[i]);
		}
		model.setViewName("displayName");
		model.addObject("Story_Ids", Employee_Ids);


		projectDAO.saveOrUpdate(project,Employee_Ids,Role_names,Platform_Ids);
		return new ModelAndView("redirect:/ProjectEmp");
	}
	@RequestMapping(value="/deleteProject", method=RequestMethod.GET)
	public ModelAndView deleteProject(HttpServletRequest request) throws IOException{

		int projectId= Integer.parseInt(request.getParameter("projectId"));
		projectDAO.delete(projectId);
		return new ModelAndView("redirect:/ProjectEmp");
	}
	//here project creation ends...

//***************************Project Backlog***************************
	@RequestMapping(value="/Project")
	public ModelAndView listProject(ModelAndView model) throws IOException{

		System.out.print(" session id is"+httpSession.getAttribute("empid"));
		int eid=(Integer)httpSession.getAttribute("empid");
		
		//**to display username on all pages**
		String username=employeeDAO.getUserName(eid);
		model.addObject("username", username);
		httpSession.setAttribute("username", username);
		
		
		List<Project> listProject = projectDAO.list(eid);
		model.addObject("listProject", listProject);

		List<PlatForm> listPlatform = platformDAO.list();
		model.addObject("listplatform", listPlatform);

		List<Status> listStatus = statusDAO.list();
		model.addObject("listStatus", listStatus);
		List<String> listprojstatus=statusDAO.listProjectStatus(eid);

		List<String> listprojclient=projectDAO.listClient(eid);
		model.addObject("listClient",listprojclient);

		model.addObject("projectStatus", listprojstatus);

		model.setViewName("Project");

		return model;
	}

	@RequestMapping(value="/logout")
	public ModelAndView logout(ModelAndView model) throws IOException{

		httpSession.invalidate();

		model.setViewName("redirect:/");

		return model;
	}




	//*********************story module***************************

	@RequestMapping(value="/Backlog")
	public ModelAndView Project(ModelAndView model ,HttpServletRequest request) throws IOException{

		String username=(String) httpSession.getAttribute("username");
		model.addObject("username", username);
		
		int pid=Integer.parseInt(request.getParameter("project_id"));
		httpSession.setAttribute("projid",pid);

		List<Story> listStory= storyDAO.list();
		model.addObject("listStory",listStory);
		List<String> listSprint= sprintDAO.listSprintNames();

		model.addObject("listStory",listStory);
		model.addObject("listSprint",listSprint);
		model.setViewName("Backlog");

		return model;
	}

	@RequestMapping(value="/CreateStory")
	public ModelAndView CreateStory(ModelAndView model) throws IOException {

		Story newStory = new Story();

		List<Status> liststatus = statusDAO.list();
		model.addObject("liststatus", liststatus);

		List<StoryPoints> liststoryPoint = storypointsDAO.list();
		model.addObject("liststorypoint", liststoryPoint);

		List<Priority> listpriority = priorityDAO.list();
		model.addObject("listpriority", listpriority);

		List<Complexity> listcomplexity = complexityDAO.list();
		model.addObject("listcomplexity", listcomplexity);

		model.addObject("story", newStory);

		model.setViewName("CreateStory");
		return model;

	}
//***************************Story details and task backlog ***************************

	@RequestMapping(value="/StoryDetails",method = RequestMethod.GET)
	public ModelAndView StoryDetails(HttpServletRequest request) throws IOException{
		

		int sid=Integer.parseInt(request.getParameter("sid"));

		Story story=storyDAO.get(sid);
		// gets the status name
		//String statusn=storyDAO.getStatus(sid);

		//gets the priority name for the story
		String priority=storyDAO.getPriority(sid);

		// gets complexity name for the story
		String complexity=storyDAO.getComplexity(sid);

		//gets the storypoint id for the story
		int story_point_id=story.getStory_point_id();

		//gets the actual story point for the story
		StoryPoints storypoint=storypointsDAO.get(story_point_id);

		//gets the priority id from the story object
		int priority_id=story.getPriority_id();

		Priority priority1=priorityDAO.get(priority_id);

		int complexity_id=story.getComplexity_id();

		Complexity complexity1=complexityDAO.get(complexity_id);

		int status_id=story.getStatus_id();

		Status status=statusDAO.get(status_id);

		List<Task> listTask = taskDAO.list(sid);  

		//to get the status of all tasks
		List<String> taskstatus=taskDAO.listStatus(sid); 

		ModelAndView model = new ModelAndView("StoryDetails");
		
		String username=(String) httpSession.getAttribute("username");
		model.addObject("username", username);
		
		model.addObject("story",story);
		//list of all tasks status
		model.addObject("taskstatus", taskstatus);
		//list of all task 
		model.addObject("listTask",listTask);
		// status of the story 
		model.addObject("status_id", status); 
		//complexity of the story
		model.addObject("complexity_id",complexity); 
		//priority of the story
		model.addObject("priority_id", priority);
		//story point for that story
		model.addObject("story_point_id", storypoint);//story point for that story
		//priority of the story
		model.addObject("priority_name", priority1);
		//complexity of the story
		model.addObject("complexity_id", complexity1);

		return model;
	}


	@RequestMapping(value = "/editStory", method = RequestMethod.GET)
	public ModelAndView editContact(HttpServletRequest request) {
		int storyId = Integer.parseInt(request.getParameter("id"));
		Story story = storyDAO.get(storyId);		



		ModelAndView model = new ModelAndView("EditStoryDetails");

		int priority_id=story.getPriority_id();
		Priority priority=priorityDAO.get(priority_id);

		int complexity_id=story.getComplexity_id();
		Complexity complexity=complexityDAO.get(complexity_id);

		int status_id=story.getStatus_id();
		Status status=statusDAO.get(status_id);

		int story_point_id=story.getStory_point_id();
		StoryPoints storypoint=storypointsDAO.get(story_point_id);



		model.addObject("story",story);

		List<Status> liststatus = statusDAO.list();
		model.addObject("liststatus", liststatus);

		List<StoryPoints> liststoryPoint = storypointsDAO.list();
		model.addObject("liststorypoint", liststoryPoint);

		List<Priority> listpriority = priorityDAO.list();
		model.addObject("listpriority", listpriority);

		List<Complexity> listcomplexity = complexityDAO.list();
		model.addObject("listcomplexity", listcomplexity);
		model.addObject("priority_name", priority);
		model.addObject("complexity_name",complexity);
		model.addObject("status_name", status);
		model.addObject("story_point", storypoint);

		return model;
	}

	@RequestMapping(value = "/saveStory", method = RequestMethod.POST)
	public ModelAndView saveStory(@ModelAttribute Story story,HttpServletRequest request) {
		//	int story_id=Integer.parseInt(request.getParameter("id"));
		int project_id=Integer.parseInt(request.getParameter("project_id"));
		//System.out.println("In Home Controller value is:"+story_id);
		System.out.println("In Home Controller value is:"+project_id);
		//task.setStory_id(1);
		storyDAO.saveOrUpdate(story,project_id);
		return new ModelAndView("redirect:/ProjectEmp");
	}

	@RequestMapping(value = "/deleteStory", method = RequestMethod.GET)
	public ModelAndView deleteContact(HttpServletRequest request) {
		int storyId = Integer.parseInt(request.getParameter("id"));
		storyDAO.delete(storyId);
		return new ModelAndView("redirect:/ProjectEmp");
	}


	@RequestMapping(value="/displayName")
	public ModelAndView displayName(ModelAndView model,HttpServletRequest request) throws IOException{
		String Story_Ids[]=request.getParameterValues("check");
		String sprintName=request.getParameter("sprint");
		System.out.println("In HomeController value of sprint is"+ sprintName);
		int sprint_id=sprintDAO.findSprintbyName(sprintName);
		System.out.println("In HomeController value of sprint id is"+ sprint_id);
		String project_id=request.getParameter("project_id");
		//int sprintId=2;
		storyDAO.MoveTo(Story_Ids, sprint_id);
		model.setViewName("redirect:/ProjectEmp");
		model.addObject("Story_Ids", Story_Ids);

		return model;
	}



	//********************task module***************************
	@RequestMapping(value="/Addtask")
	public ModelAndView Addtask(ModelAndView model) throws IOException{
		Task newTask = new Task();
		
		int pid=(Integer)httpSession.getAttribute("projid");
		List<Employee> listemployee = employeeDAO.listProjectEmployees(pid);
		model.addObject("listemployee", listemployee);	
		
		List<Status> listStatus = statusDAO.list();
		List<Complexity> listcomplexity = complexityDAO.list();
		int status_id=newTask.getStatus_id();
		Status status=statusDAO.get(status_id);
		int complexity_id=newTask.getComplexity_id();
		model.addObject("listcomplexity", listcomplexity);
		model.addObject("listStatus", listStatus);
		model.addObject("task", newTask);
		model.addObject("status_id", status);
		model.addObject("complexity_id", complexity_id);
		model.setViewName("Addtask");

		return model;
	}

	@RequestMapping(value="/EditTask",method = RequestMethod.GET)
	public ModelAndView EditTask(HttpServletRequest request) throws IOException{
		int tid=Integer.parseInt(request.getParameter("tid"));
		System.out.print("tid is:"+tid);

		Task task=taskDAO.get(tid);
		int status_id=task.getStatus_id();

		String statusn=taskDAO.getStatus(tid);
		String complexityn=taskDAO.getComplexity(tid);

		Status status=statusDAO.get(status_id);
		List<Status> listStatus=statusDAO.list();

		int complexity_id=task.getComplexity_id();
		Complexity complexity=complexityDAO.get(complexity_id);
		List<Complexity> listComplexity=complexityDAO.list();

		ModelAndView model = new ModelAndView("EditTaskDetails");
		model.addObject("task",task);
		model.addObject("statusid", status_id);
		model.addObject("status_id",status);
		model.addObject("listStatus",listStatus);//list of status
		model.addObject("complexity_id",complexity);//complexity object
		model.addObject("complexityn", complexityn);//selected complexity name
		model.addObject("complexityid", complexity_id);//selected complexity_id
		model.addObject("statusn", statusn);//selected status name
		model.addObject("listComplexity",listComplexity);//list of Complexity
		return model;
	}

	@RequestMapping(value="/saveTask", method=RequestMethod.GET)
	public ModelAndView saveTask(@ModelAttribute Task task,HttpServletRequest request) throws IOException
	{
		System.out.println("the obbbject task id is:"+task.getTask_id());
		taskDAO.saveOrUpdate(task);
		return new ModelAndView("redirect:/ProjectEmp");
	}

	@RequestMapping(value="/deleteTask",method=RequestMethod.GET)
	public ModelAndView deleteTask(HttpServletRequest request) {
		int taskid= Integer.parseInt(request.getParameter("tid"));
		System.out.print("the task_id is "+ taskid);
		taskDAO.delete(taskid);
		return new ModelAndView("redirect:/ProjectEmp");
	}





	//**************sprint tracking***************************


	@RequestMapping(value="/Storyboard1")
	public ModelAndView Storyboard1(ModelAndView model) throws IOException{

		String username=(String) httpSession.getAttribute("username");
		model.addObject("username", username);
		
		model.setViewName("Storyboard1");

		return model;
	}
	@RequestMapping(value="/Taskboard1")
	public ModelAndView Taskboard1(ModelAndView model) throws IOException{

		model.setViewName("Taskboard1");

		return model;
	}


	@RequestMapping(value="/Addtask1" ,method = RequestMethod.GET)
	public ModelAndView Addtask1(ModelAndView model, @ModelAttribute Task Task, HttpServletRequest request) throws IOException{
		int taskId = Integer.parseInt(request.getParameter("task_id"));
		//System.out.println("Task id :"+ taskId);

		Task task = taskDAO.get(taskId);
		model.addObject("task", task);

		List<Status> liststatus = statusDAO.list();
		model.addObject("liststatus", liststatus);

		List<Complexity> listcomplexity = complexityDAO.list();
		model.addObject("listcomplexity", listcomplexity);

		int status_id=task.getStatus_id();
		Status status=statusDAO.get(status_id);
		model.addObject("status_name", status);

		int complexity_id=task.getComplexity_id();
		Complexity complexity=complexityDAO.get(complexity_id);
		model.addObject("complexity_name", complexity);

		model.addObject("Addtask1");
		return model;
	}



	@RequestMapping(value="/StoryDetails1", method = RequestMethod.GET)
	public ModelAndView StoryDetails1(ModelAndView model, @ModelAttribute Story story, HttpServletRequest request) throws IOException{

		int storyId= Integer.parseInt(request.getParameter("story_id"));
		//System.out.println("Stroy id :"+storyId);

		List<Status> liststatus = statusDAO.list();
		model.addObject("liststatus", liststatus);


		List<Priority> listpriority = priorityDAO.list();
		model.addObject("listpriority", listpriority);

		List<Complexity> listcomplexity = complexityDAO.list();
		model.addObject("listcomplexity", listcomplexity);


		story = storyDAO.get(storyId);
		model.addObject("story", story);
		model.setViewName("StoryDetails1");
		return model;
	}	

	//***************************admin code***************************
	/*
	 * Adding, displaying, updating role form*/
	@RequestMapping(value="/Addrole")
	public ModelAndView Addrole(ModelAndView model) throws IOException{
		Role newRole = new Role();
		model.addObject("role", newRole);
		List<Role> listRole = roleDAO.list();
		model.addObject("listRole", listRole);
		model.setViewName("Addrole");
		return model;

	}

	@RequestMapping(value="/saveRole", method=RequestMethod.POST)
	public ModelAndView saveRole(@ModelAttribute Role role)
	{
		roleDAO.saveOrUpdate(role);
		return new ModelAndView("redirect:/Addrole");
	}

	@RequestMapping(value = "/deleteRole")
	public ModelAndView deleteRole(HttpServletRequest request) {
		int roleId = Integer.parseInt(request.getParameter("roleId"));
		roleDAO.delete(roleId);
		return new ModelAndView("redirect:/Addrole");
	}	

	@RequestMapping(value = "/editRole")
	public ModelAndView editRole(HttpServletRequest request) {
		int roleId = Integer.parseInt(request.getParameter("roleId"));
		Role role = roleDAO.get(roleId);
		ModelAndView model = new ModelAndView("RoleForm");
		model.addObject("role", role);	
		return model;
	}

	/*
	 * Adding,displaying, updating storypoints form*/

	@RequestMapping(value="/AddStoryPoints")
	public ModelAndView AddStoryPoints(ModelAndView model) throws IOException{
		StoryPoints newStorypoint = new StoryPoints();
		model.addObject("storypoint", newStorypoint);

		List<StoryPoints> listStoryPoint = storypointsDAO.list();
		model.addObject("listStoryPoint", listStoryPoint);
		model.setViewName("AddStoryPoints");
		return model;

	}

	@RequestMapping(value="/saveStoryPoint", method=RequestMethod.POST)
	public ModelAndView saveStoryPoint(@ModelAttribute StoryPoints storypoint)
	{
		storypointsDAO.saveOrUpdate(storypoint);
		return new ModelAndView("redirect:/AddStoryPoints");
	}

	@RequestMapping(value = "/deleteStoryPoint", method = RequestMethod.GET)
	public ModelAndView deleteStoryPoint(HttpServletRequest request) {
		int storypointId = Integer.parseInt(request.getParameter("story_point_id"));
		storypointsDAO.delete(storypointId);
		return new ModelAndView("redirect:/AddStoryPoints");
	}	

	@RequestMapping(value = "/editStoryPoint", method = RequestMethod.GET)
	public ModelAndView editStoryPoint(HttpServletRequest request) {
		int storyPointId = Integer.parseInt(request.getParameter("story_point_id"));

		StoryPoints storypoint=storypointsDAO.get(storyPointId);
		List<StoryPoints> listStoryPoint = storypointsDAO.list();

		ModelAndView model = new ModelAndView("AddStoryPoints");
		model.addObject("storypoint", storypoint);	
		model.addObject("listStoryPoint", listStoryPoint);

		return model;
	}
	///ends here story points


	/*
	 * Adding, displaying, updating Client form*/
	@RequestMapping(value="/AddClient")
	public ModelAndView AddClient(ModelAndView model) throws IOException{
		Client newClient = new Client();
		model.addObject("client", newClient);
		List<Client> listClient = clientDAO.list();
		model.addObject("listClient", listClient);
		model.setViewName("AddClient");
		return model;
	}

	@RequestMapping(value="/saveClient", method=RequestMethod.POST)
	public ModelAndView saveClient(@ModelAttribute Client client)
	{
		clientDAO.saveOrUpdate(client);
		return new ModelAndView("redirect:/AddClient");
	}

	@RequestMapping(value = "/deleteClient",method = RequestMethod.GET)
	public ModelAndView deleteClient(HttpServletRequest request) {
		int clientId = Integer.parseInt(request.getParameter("client_id"));
		clientDAO.delete(clientId);
		return new ModelAndView("redirect:/AddClient");
	}	

	@RequestMapping(value = "/editClient",method = RequestMethod.GET)
	public ModelAndView editClient(HttpServletRequest request) {
		int clientId = Integer.parseInt(request.getParameter("client_id"));
		System.out.println("Client id :"+ clientId);
		Client client = clientDAO.get(clientId);
		ModelAndView model = new ModelAndView("ClientForm");
		model.addObject("client", client);	
		return model;
	}
	//ends here client form...

	/*
	 * Adding,displaying, updating platform form*/

	@RequestMapping(value="/Platform")
	public ModelAndView AddPlatform(ModelAndView model) throws IOException{
		PlatForm newPlatform = new PlatForm();
		model.addObject("platform", newPlatform);
		List<PlatForm> listPlatform = platformDAO.list();
		model.addObject("listPlatform", listPlatform);
		model.setViewName("Platform");
		return model;
	}

	@RequestMapping(value="/savePlatform", method=RequestMethod.POST)
	public ModelAndView savePlatform(@ModelAttribute PlatForm platform)
	{
		platformDAO.saveOrUpdate(platform);
		return new ModelAndView("redirect:/Platform");
	}

	@RequestMapping(value = "/deletePlatform", method = RequestMethod.GET)
	public ModelAndView deletePlatform(HttpServletRequest request) {
		int platformId = Integer.parseInt(request.getParameter("platform_id"));
		//System.out.println("platform ID="+ platformId);
		platformDAO.delete(platformId);
		return new ModelAndView("redirect:/Platform");
	}	

	@RequestMapping(value = "/editPlatform", method = RequestMethod.GET)
	public ModelAndView editPlatform(HttpServletRequest request) {
		int platformId = Integer.parseInt(request.getParameter("platform_id"));
		PlatForm platform = platformDAO.get(platformId);
		ModelAndView model = new ModelAndView("PlatformForm");
		model.addObject("platform", platform);	
		return model;
	}
	//here ends the platform...


	//*************************** employee code starts***************************
	
	@RequestMapping(value="/Addemp")
	public ModelAndView listEmployee(ModelAndView model) throws IOException{

		Employee newEmployee = new Employee();
		model.addObject("employee", newEmployee);
		List<Designation> designationList = designationDAO.list();
		model.addObject("designationList", designationList);
		//List<Employee> listEmployee = employeeDAO.list();
		//model.addObject("listEmployee", listEmployee);
		model.setViewName("Addemp");
		return model;

	}

	@RequestMapping(value = "/saveEmployee", method = RequestMethod.POST)
	public ModelAndView saveEmployee(@ModelAttribute Employee employee,BindingResult result,SessionStatus status) {
		employeeDAO.saveOrUpdate(employee);		
		return new ModelAndView("redirect:/Addemp");
	}

	
	@RequestMapping(value = "/deleteEmployee", method = RequestMethod.GET)
	public ModelAndView deleteEmployee(HttpServletRequest request) {
		int employeeId = Integer.parseInt(request.getParameter("id"));
		//System.out.println("employee id is "+ employeeId);
		employeeDAO.delete(employeeId);
		return new ModelAndView("redirect:/Addemp");
	}

	@RequestMapping(value = "/EmpForm", method = RequestMethod.GET)
	public ModelAndView editEmployee(HttpServletRequest request) {
		int employeeId = Integer.parseInt(request.getParameter("id"));
		Employee employee = employeeDAO.get(employeeId);

		List<Designation> designationList = designationDAO.list();

		int designationId = employee.getDesignation_id();
		Designation designation = designationDAO.get(designationId);

		ModelAndView model = new ModelAndView("EmpForm");
		model.addObject("employee", employee);
		model.addObject("designationList", designationList);
		model.addObject("designationName", designation);
		return model;
	}


	
	//************sprint planning***************
	@RequestMapping(value="/SprintPlanning")
	public ModelAndView SprintPlanning(@ModelAttribute Sprint sprint , HttpServletRequest req) throws IOException{

		ModelAndView mav = new ModelAndView("SprintPlanning");
		List<Sprint> sprintList = sprintDAO.listSprint();
		List<Story> storyList = storyDAO.getUnscheduledStory();
		
		String username=(String) httpSession.getAttribute("username");
		mav.addObject("username", username);
		mav.addObject("sprintList" , sprintList);
		mav.addObject("storyList" , storyList);

		return mav;
	}

	@RequestMapping(value="/saveSprint")
	public ModelAndView saveSprint(@ModelAttribute Sprint sprint , HttpServletRequest req) throws IOException
	{
		ModelAndView mav = new ModelAndView("SprintPlanning");
		List<Sprint> sprintList = sprintDAO.listSprint();
		List<Story> storyList = storyDAO.getUnscheduledStory();
		//	int project_id = Integer.parseInt(req.getParameter("project_id"));

		sprintDAO.saveOrUpdate(sprint);
		mav.addObject("sprintList" , sprintList);
		mav.addObject("storyList" , storyList);

		return mav;
	}

	@RequestMapping(value="/moveToSprint")
	public ModelAndView moveToSprint(@ModelAttribute Sprint sprint , HttpServletRequest req)
	{
		ModelAndView mav = new ModelAndView("SprintPlanning");
		List<Sprint> sprintList = sprintDAO.listSprint();
		List<Story> storyList = storyDAO.getUnscheduledStory();
		int sprintId = Integer.parseInt(req.getParameter("sprintId"));
		String sList[] = req.getParameterValues("sList");

		sprintDAO.storyToSprint(sList , sprintId);

		mav.addObject("sprintList" , sprintList);
		mav.addObject("storyList" , storyList);

		return mav;
	}

}
